package Jisuanqi;


import java.awt.Color;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class Average_Score {
    private int a;
    private double c = 0;
    private double d = 0;
    private int e;
    private String f;
    private static JFrame h = new JFrame( );
    private static JLabel i = new JLabel(); //标签
    private static JLabel j = new JLabel();

    public Average_Score() throws IOException{

        BufferedReader input = new BufferedReader(new FileReader("信息收集.txt"));
        while(( f = input.readLine() ) != null)
        {
            System.out.println(input.readLine());
            String k[] = f.split("：");
            a = Integer.parseInt((k[1]));
            c = c + a;
            e ++;
        }

        d = c / e;

        if(e == 0) {
            d = 0;
        }

        h.setTitle("平均分查看");
        h.setLayout(null); //取消默认布局
        h.setSize(400,180); //设置大小
        h.setLocationRelativeTo(null); //使窗口显示在屏幕中央
        h.getContentPane().setBackground(Color.YELLOW); //内容面板背景

        i.setText("参加考试人数为    "+e);
        h.getContentPane().add(i);
        i.setBounds(45, 15, 120, 50);

        j.setText("平均分为    "+d);
        h.getContentPane().add(j);
        j.setBounds(45, 50, 120, 50);

        h.setVisible(true);
    }
}
